﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace Nx.Clients.Http
{
    public class JsonSerializer : ISerializer
    {
        public string MediaType
        {
            get { return "application/json"; }
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        public string Serialize<T>(T dto)
        {
            return JsonConvert.SerializeObject(dto);
        }

        public T Deserialize<T>(string jsonString)
        {
            return JsonConvert.DeserializeObject<T>(jsonString);
        }

        public IEnumerable<T> DeserializeCollection<T>(string jsonString)
        {
            return JsonConvert.DeserializeObject<T[]>(jsonString);
        }
    }
}
